/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2022-12-02
 * Time: 15:57
 */
public class test {
}
 class PalindromeList {
    public boolean chkPalindrome(ListNode A) {
        // write code here
        if(A==null){
            return false;
        }
        if(A.next==null){
            return true;
        }
        ListNode fast=A;
        ListNode slow=A;
        while (fast!=null  &&  fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
        }
        ListNode cur=slow.next;

        while (cur!=null){
            ListNode curNext;
            curNext=cur.next;
            cur.next=slow;
            slow=cur;
            cur=curNext;
        }
        ListNode head=A;
        while (head!=slow){
            if(head.val!=slow.val){
                return false;
            }
            if(head.next==slow){
                return true;
            }
            head=head.next;
            slow=slow.next;
        }
        return true;
    }
}